#include "config.h"
#include "Util/logger.h"
using namespace std;

using namespace toolkit;

bool loadIniConfig(const char *ini_path) {
    string ini;
    if (ini_path && ini_path[0] != '\0') {
        ini = ini_path;
    } else {
        ini = exePath() + ".ini";
    }
    try {
        mINI::Instance().parseFile(ini);
        return true;
    } catch (std::exception &) {
        InfoL << "dump ini file to:" << ini;
        mINI::Instance().dumpFile(ini);
        return false;
    }
}

namespace COF_CMS{
    #define COF_CMS_FIELD "CMS."
    const string kenable = COF_CMS_FIELD "enable";
    const string kReceiveNum = COF_CMS_FIELD "ReceiveNum";
    const string kCenterIP = COF_CMS_FIELD "CenterIP";
    const string kCenterPort = COF_CMS_FIELD "CenterPort";
    const string kLineNum = COF_CMS_FIELD "LineNum";
    const string kCommPro = COF_CMS_FIELD "Communication protocol";
    const string kHeartBeat = COF_CMS_FIELD "HeartBeat";

    
    
static onceToken token([]() {
    mINI::Instance()[kenable] = 1;
    mINI::Instance()[kReceiveNum] = 0;
    mINI::Instance()[kCenterIP] = "127.0.0.1";
    mINI::Instance()[kCenterPort] = 5080;
    mINI::Instance()[kLineNum] = 1;
    mINI::Instance()[kCommPro] = "tcp";
    mINI::Instance()[kHeartBeat] = 5;
});
};

namespace COF_DEVICE {
    #define COF_DEVICE_FIELD "DEVICE."
    const string kenable = COF_DEVICE_FIELD "enable";
    const string kHostAddress = COF_DEVICE_FIELD "HostAddress";
    const string kDevicePort = COF_DEVICE_FIELD "DevicePort";
    const string kOnlineCode = COF_DEVICE_FIELD "OnlineCode";
    const string kOfflineCode = COF_DEVICE_FIELD "OfflineCode";
    const string kHeartBeat = COF_DEVICE_FIELD "HeartBeat";
    const string kEncryptionKey = COF_DEVICE_FIELD "EncryptionKey";

static onceToken token([]() {
    mINI::Instance()[kenable] = 1;
    mINI::Instance()[kHostAddress] = "127.0.0.1";
    mINI::Instance()[kDevicePort] = 5090;
    mINI::Instance()[kOnlineCode] = "1";
    mINI::Instance()[kOfflineCode] = "0";
    mINI::Instance()[kHeartBeat] = 1;
    mINI::Instance()[kEncryptionKey] = "xxxxxx";

});

};

